<!-- script type="text/javascript">
$(document).ready(function() {

	$('#btnCari').click(function(){	
		$('#searchResult').html('');
		$('#searchResult').html('<div align="center"><img src="img/loading-1.gif" />&nbsp;&nbsp;Searching</div>');

		$.ajax({
			url: 'tasks/add',
			data : $("#searchIndividu").serialize(),
			dataType: 'json',
			type : 'post',
			//beforeSubmit:  showRequest,  // pre-submit callback 
			success: function(data){
				alert(data);
			}
			});
	
		return false;
	});
});
</script-->



<script>
function makepage(src)
{
  // We break the closing script tag in half to prevent
  // the HTML parser from seeing it as a part of
  // the *main* page.

  return "<html>\n" +
    "<head>\n" +
    "<title>Temporary Printing Window</title>\n" +
    "<script>\n" +
    "function step1() {\n" +
    "  setTimeout('step2()', 10);\n" +
    "}\n" +
    "function step2() {\n" +
    "  window.print();\n" +
    "  window.close();\n" +
    "}\n" +
    "</scr" + "ipt>\n" +
    "</head>\n" +
    "<body onLoad='step1()'>\n" +
    "<img src='" + src + "'/>\n" +
    "</body>\n" +
    "</html>\n";
}

function printme(evt)
{
  if (!evt) {
    // Old IE
    evt = window.event;
  }    
  var image = evt.target;
  if (!image) {
    // Old IE
    image = window.event.srcElement;
  }
  src = image.src;
  link = "about:blank";
  var pw = window.open(link, "_new");
  pw.document.open();
  pw.document.write(makepage(src));
  pw.document.close();
}
</script>

<div class="top-bar">
					<h1>Asset</h1>
					<div class="breadcrumbs">
						<a href="/">Laman Utama</a> / <a href="#">Asset</a> / <a href="#">Carian</a>
					</div>
				</div>
				<br />
				<div class="select-bar" style="border-bottom:0px">
</div>
<div class="grid_12">
	<div class="box">
		<div class="items index">
			<h2>
			<?php __('Search');?>
			</h2>
			<div class="box">
			<form accept-charset="utf-8" method="post" id="PostSearchForm" action="/asset/items/search">
				<div style="display:none;">
					<input type="hidden" value="POST" name="_method">
				</div>
				<div align="center" style="padding-bottom: 10px;">
					<label for="PostQ">Search for</label><input type="text" id="PostQ" name="data[Item][q]"  style="width: 260px; height: 35px;padding-left: 5px;">
					<input type="submit"  value="CARI" id="btnCari" style="height:26px;font-size:12px; width:80px;  font-weight:bold;" /> 
				</div>
			</form>			
			</div>
			<div class="result">
				<div id="searchResult">
				
				<?php if(empty($item)) { ?>
				
				<p align="center"><?=$message?></p>
				
				<?php }
				else { ?>
				<div class="items view">
<?php 
		$data_to_encode = "KDN/PDRM/SMS/CK/PR/09/H/11/".str_pad($item['Item']['id'], 6, '0',STR_PAD_LEFT);
		$barcode->barcode(); 
		$barcode->setType('C128');
		$barcode->setCode($data_to_encode);
		$barcode->setSize(80,200);

		// Generate filename
		$random = rand(0,1000000);
		$file = 'img/barcode/code_'.$random.'.jpg';

		// Generates image file on server
		$barcode->writeBarcodeFile($file);

		?>
	<div class="table">
				<img src="../../img/bg-th-left.gif" width="8" height="7" alt="" class="left" />
				<img src="../../img/bg-th-right.gif" width="7" height="7" alt="" class="right" />
				<?php echo $this->Form->create('Item');?>
				<table class="listing form" cellpadding="0" cellspacing="0">
					<tr>
						<th class="full" colspan="2">Asset <?php echo $data_to_encode?></th>
					</tr>
					<tr>
						<td class="first" width="172"><strong>Barkod</strong></td>
						<td class="last"><?php echo '<a href="#" onClick="printme(event)">
								<img style="border:1px solid grey;"  src="/asset/img/barcode/code_'.$random.'.jpg" alt="print" /></a>';?></td>
					</tr>
					<tr class="bg">
						<td class="first" width="172"><strong>Nama Model</strong></td>
						<td class="last"><?php echo $item['Item']['name']; ?></td>
					</tr>
					<tr>
						<td class="first" width="172"><strong>Kod Nasional</strong></td>
						<td class="last"><?php echo $item['Item']['national_code']; ?></td>
					</tr>
					<tr class="bg">
						<td class="first"><strong>Kategori</strong></td>
						<td class="last"><?php echo $this->Html->link($item['Category']['name'], array('controller' => 'categories', 'action' => 'view', $item['Category']['id'])); ?></td>
					</tr>
					<tr>
						<td class="first""><strong>Jenis</strong></td>
						<td class="last"><?php echo $this->Html->link($item['Type']['name'], array('controller' => 'types', 'action' => 'view', $item['Type']['id'])); ?></td>
					</tr>
					<tr class="bg">
						<td class="first"><strong>Buatan</strong></td>
						<td class="last"><?php echo $this->Html->link($item['Origin']['name'], array('controller' => 'origins', 'action' => 'view', $item['Origin']['id'])); ?></td>
					</tr>
					<tr>
						<td class="first"><strong>Pembekal</strong></td>
						<td class="last"><?php echo $this->Html->link($item['Supplier']['name'], array('controller' => 'suppliers', 'action' => 'view', $item['Supplier']['id'])); ?></td>
					</tr>
					<tr class="bg">
						<td class="first"><strong>No Siri Pembuat</strong></td>
						<td class="last"><?php echo $item['Item']['manufacturer_serial_no']; ?></td>
					</tr>
					<tr>
						<td class="first"><strong>Harga Perolehan</strong></td>
						<td class="last"><?php echo $this->Number->currency($item['Item']['price'],"MYR"); ?></td>
					</tr>
					<tr class="bg">
						<td class="first"><strong>Tarikh Diterima</strong></td>
						<td class="last"><?php echo $item['Item']['received_date']; ?></td>
					</tr>
					<tr>
						<td class="first"><strong>Tempoh Jaminan</strong></td>
						<td class="last"><?php echo $item['Item']['warranty_period']; ?></td>
					</tr>
					<tr class="bg">
						<td class="first"><strong>Catatan</strong></td>
						<td class="last"><?php echo $item['Item']['remarks']; ?></td>
					</tr>
					<?php
						// if the post has an image display it
						if(!empty($item['Item']['image_url'])) :
							$url = $item['Item']['image_url'];
					?>
					<tr>
						<td class="first"><strong>Gambar</strong></td>
						<td class="last"><?php echo '<a target="_blank" href="/asset/'.$url.'"><img width="100" height="100" style="border-style:solid" src="/asset/'.$url.'" alt="Upload Image" /></a>';?></td>
					</tr>
					<?php endif; ?>
				</table>
				<br />
				<div align="right">[<?php echo $this->Html->link("KEMASKINI", array('action' => 'edit', $item['Item']['id'])); ?>]</div>
		</div>
<!--  2nd option: put the table penempatan here then it will be hidden if no field enter -->
</div>
<div class="clear"></div>

<?php } ?>
				
				</div>
			</div>
		</div>
	</div>
</div>
<?php if(!empty($item)) :?>
<div class="table">
<table class="listing" cellpadding="0" cellspacing="0">
<tr>
<th colspan="5">Penempatan</th>
</tr>
<tr>
<th>Bil.</th>
<th>Lokasi</th>
<th>Tarikh</th>
<th>Nama Pegawai</th>
<th class="actions"><?php __('Actions');?></th>
</tr>
<?php if(count($locations)<= 0) : ?>
<tr>
	<td colspan="5"><div align="center" class="error">TIADA REKOD UNTUK PENEMPATAN</div>
	</td>
</tr>
<?php
	endif;
	$i = 0;
	foreach ($locations as $location):
		$class = null;
		if ($i++ % 2 == 0) {
			$class = ' class="altrow"';
		}
	?>
	<tr<?php echo $class;?>>
		<td><?php echo $i;?></td>
		<td><?php echo $location['District']['name']; ?>&nbsp;</td>
		<td><?php echo $location['Location']['date']; ?>&nbsp;</td>
		<td><?php echo $location['Location']['pic']; ?>&nbsp;</td>
		<td class="actions">
			<?php echo $this->Html->link($this->Html->image("hr.gif"), array('controller'=>'locations','action' => 'delete', $location['Location']['id']), array('escape' => false), sprintf(__('Are you sure you want to delete # %s?', true), $location['Location']['id'])); ?>
		</td>
		
	</tr>
	<?php endforeach; ?>
</table>
<br />
<div align="right">[<?php echo $this->Html->link("Tambah", array('controller'=>'locations','action' => 'add', $item['Item']['id'])); ?>]&nbsp;</div>
</div>

<div class="table">
<table class="listing" cellpadding="0" cellspacing="0">
<tr>
<th colspan="6">Pemeriksaan</th>
</tr>
<tr>
<th>Bil.</th>
<th>Tarikh</th>
<th>Status Asset</th>
<th>Nama Pemeriksa</th>
<th>Catatan</th>
<th class="actions"><?php __('Actions');?></th>
</tr>
<?php if(count($inspections)<= 0) : ?>
<tr>
	<td colspan="6"><div align="center" class="error">TIADA REKOD UNTUK PEMERIKSAAN</div>
	</td>
</tr>
<?php
endif;
	$i = 0;
	foreach ($inspections as $inspection):
		$class = null;
		if ($i++ % 2 == 0) {
			$class = ' class="altrow"';
		}
	?>
	<tr<?php echo $class;?>>
		<td><?php echo $i;?></td>
		<td><?php echo $inspection['Inspection']['date']; ?>&nbsp;</td>
		<td><?php echo $inspection['Status']['name']; ?>&nbsp;</td>
		<td><?php echo $inspection['Inspection']['name']; ?>&nbsp;</td>
		<td><?php echo $inspection['Inspection']['remark']; ?>&nbsp;</td>
		<td class="actions">
			<?php echo $this->Html->link($this->Html->image("hr.gif"), array('controller'=>'inspections','action' => 'delete', $inspection['Inspection']['id']), array('escape' => false), sprintf(__('Are you sure you want to delete # %s?', true), $inspection['Inspection']['id'])); ?>
		</td>
	</tr>
	<?php endforeach; ?>
</table>
<br />
<div align="right">[<?php echo $this->Html->link("Tambah", array('controller'=>'inspections','action' => 'add', $item['Item']['id'])); ?>]&nbsp;</div>
</div>

<div class="table">
<table class="listing" cellpadding="0" cellspacing="0">
<tr>
<th colspan="4">Pelupusan/Hapuskira</th>
</tr>
<tr>
<th>Rujukan Kelulusan</th>
<th>Tarikh</th>
<th>Kaedah Pelupusan</th>
<th class="actions"><?php __('Actions');?></th>
</tr>
<?php if(count($disposals)<= 0) : ?>
<tr>
	<td colspan="5"><div align="center" class="error">TIADA REKOD UNTUK PELUPUSAN</div>
	</td>
</tr>
<?php
endif;
	$i = 0;
	foreach ($disposals as $disposal):
		$class = null;
		if ($i++ % 2 == 0) {
			$class = ' class="altrow"';
		}
	?>
	<tr<?php echo $class;?>>
		<td><?php echo rand(19231, 9999); ?>&nbsp;</td>
		<td><?php echo $disposal['Disposal']['disposal_date']; ?>&nbsp;</td>
		<td><?php echo $disposal['Disposal']['details']; ?>&nbsp;</td>
		<td class="actions">
			<?php echo $this->Html->link($this->Html->image("hr.gif"), array('action' => 'delete', $disposal['Disposal']['id']), array('escape' => false), sprintf(__('Are you sure you want to delete # %s?', true), $disposal['Disposal']['id'])); ?>
		</td>
	</tr>
	<?php endforeach; ?>
</table>
<br />
<div align="right">[<?php echo $this->Html->link("Tambah", array('controller'=>'disposals','action' => 'add', $item['Item']['id'])); ?>]&nbsp;</div>
</div>
<?php endif;?>
<div class="clear"></div>
